package com.chiry.shop.order.service.impl;

import com.chiry.common.vo.Result;
import com.chiry.common.vo.param.OrderParam;
import com.chiry.shop.order.mapper.OrderMapper;
import com.chiry.shop.order.pojo.Order;
import com.chiry.shop.order.service.OrderService;
import org.apache.commons.lang3.RandomUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Random;

/**
 * @author fyx
 * @version 1.0
 * @date 2021/12/9 20:40
 */
@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper;
    @Override
    public Result<String> createOrder(OrderParam orderParam) {
        Order order = new Order();
        order.setUserId(orderParam.getUserId());
        order.setGoodsId(orderParam.getGoodsId());
        order.setOrderPrice(orderParam.getGoodsPrice());
        order.setCreateTime(System.currentTimeMillis());
        order.setOrderId(System.currentTimeMillis()+""+orderParam.getUserId()+""+orderParam.getUserId()+
        ""+RandomUtils.nextInt(1000,9999));
        order.setOrderStatus(0);
        order.setPayStatus(0);
        order.setPayTime(-1L);
        this.orderMapper.insert(order);
        return Result.success(order.getOrderId());
    }
}
